﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_WarrantyStatus
    {
    	#region public properties
		[Required(ErrorMessage="WarrantyStatusID Required")]
		public int WarrantyStatusID { get; set; }
		public string WarrantyStatusName { get; set; }
		public bool? Disabled { get; set; }
		#endregion

		#region constructor
		public pa_WarrantyStatus(){ }

		public pa_WarrantyStatus(IDataReader rd)
		{
			this.WarrantyStatusID = (int)rd["WarrantyStatusID"];
			this.WarrantyStatusName = rd["WarrantyStatusName"].ToString();
			this.Disabled = rd["Disabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Disabled"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBpa_WarrantyStatus.Create(WarrantyStatusName, Disabled);
        }

        private bool Update()
        {
            return DBpa_WarrantyStatus.Update(WarrantyStatusID, WarrantyStatusName, Disabled);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(WarrantyStatusID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int WarrantyStatusID)
        {
            return DBpa_WarrantyStatus.Delete(WarrantyStatusID);
        }

        public static List<pa_WarrantyStatus> GetAll()
        {
            return ObjectClass.CreateList<pa_WarrantyStatus>(DBpa_WarrantyStatus.GetAll());
        }

        public static pa_WarrantyStatus GetByKey(int WarrantyStatusID)
        {
            return ObjectClass.CreateInstance<pa_WarrantyStatus>(DBpa_WarrantyStatus.GetByKey(WarrantyStatusID));
        }

        public static List<pa_WarrantyStatus> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_WarrantyStatus>(DBpa_WarrantyStatus.GetByTop(top, where, order));
        }
		#endregion
	}
}
